package com.example.demo.hadoop.reduce.reducer;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class TemperatureReduce extends Reducer<Text, IntWritable, Text,IntWritable> {
    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        int maxValue = Integer.MIN_VALUE;
        StringBuffer sb = new StringBuffer();
        for(IntWritable value:values){
            maxValue = Math.max(maxValue,value.get());
            sb.append(value).append(", ");
        }
        System.out.println("Before Reduce: "+key+", "+sb.toString());
        context.write(key,new IntWritable(maxValue));
        System.out.println("====="+"After Reduce: "+key+", "+maxValue);
    }
}
